package com.example.controller;

import com.example.result.ReturnCode;
import com.example.result.ReturnResult;
import com.example.service.IBOMService;
import com.example.service.IPartService;
import com.example.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/BOMLink")
@CrossOrigin
public class BOMController {

    @Autowired
    IBOMService ibomService;

    @PostMapping("/querySonItem")
    public ReturnResult querySonItem(@RequestBody BOMLinkQuerySonItemParamVO bomLinkQuerySonItemParamVO){
        return ibomService.querySonItem(bomLinkQuerySonItemParamVO);
    }

    @PostMapping("/queryParentItem")
    public ReturnResult queryParentItem(@RequestBody BOMLinkQueryParentItemParamVO bomLinkQueryParentItemParamVO){
        return ibomService.queryParentItem(bomLinkQueryParentItemParamVO);
    }

    @PostMapping("/create")
    public ReturnResult create(@RequestBody BOMLinkCreateParamVO bomLinkCreateParamVO){
        return ibomService.create(bomLinkCreateParamVO);
    }

    @Autowired
    IPartService iPartService;

    @PostMapping("/queryPart")
    public ReturnResult queryPart(@RequestBody PartQueryParamVO partQueryParamVO){
        return iPartService.query(partQueryParamVO);
    }

    @DeleteMapping("/delete/{bomLinkId}")
    public ReturnResult delete(@PathVariable String bomLinkId){
        return ibomService.delete(bomLinkId);
    }

    @PutMapping("/update")
    public ReturnResult update(@RequestBody BomLinkUpdateParamVO bomLinkUpdateParamVO){
        return ibomService.update(bomLinkUpdateParamVO);
    }

    @GetMapping("/listQuery/{masterId}")
    public ReturnResult listQuery(@PathVariable String masterId){
        return new ReturnResult(ReturnCode.GET_OK,"查询bom清单成功",ibomService.listQuery(ibomService.findDetail(masterId)));
    }
}
